package it.tukano.treditor.modules;

import it.tukano.app.AbstractAppModule;
import it.tukano.treditor.engine.scene.SceneElement;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

public class TreditorFileWriter extends AbstractAppModule {

    /**
     * Instance initializer
     */
    public TreditorFileWriter() {
    }

    public String doSaveTreditorFile(OutputStream out) throws IOException {
        final DataModel dataModel = find(DataModel.class);
        final SceneElement sceneRoot = dataModel.getSceneRoot();
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(out);
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(bufferedOutputStream);
        objectOutputStream.writeObject(sceneRoot);
        objectOutputStream.flush();
        objectOutputStream.close();
        return null;
    }
}
